<?php
	$pictures = array(); 
	$albumlist =array();
	if(!user_input('album')) {
		$albumname =  $config['name'];
		$path = $config['photodir'];
	} else {
		$albumname =  user_input('album');
		$path = $config['photodir'] . user_input('album') ."/";
		$subpath = user_input('album') ."/";
		$dirparts = explode('/', $path);
		unset($dirparts[(count($dirparts)-1)]);
		foreach($dirparts as $curdir){ 
		if($curdir.'/' != $config['photodir'] && $curdir != end($dirparts)){
			$back .= $curdir ."/";
		}
		}
		$back = substr($back, 0, -1);
		$smarty->assign('base', $config["basedir"]);
		if($config["mod_rewrite"]){
			$smarty->assign('Upurl', "{$base}album/{$back}");
		}else{
			$smarty->assign('Upurl',"index.php?album={$back}");
		}
	}
	$dir_handle = @opendir($path) or die("You do not have permission to view - $path");
	while ($file = readdir($dir_handle)) 
	{
		if($file!="." && $file!=".." && !in_array($file,$config['hide'])){
			$fullpath = $path . $file;
			$spath = $subpath . $file;
			if(is_dir($path . $file) == TRUE) {
				if($config["mod_rewrite"]){
					array_push($albumlist, array("{$base}album/{$spath}/", $file));
				}else{
					array_push($albumlist, array("index.php?album={$spath}",$file));
				}
			} else {
				if($file{0} != "."){
					$fileparts = explode('.',$file);
					$laalbum = user_input('album');
					if(in_array(strtolower(end($fileparts)), $config['ext'])	)
					if($config["mod_rewrite"]){
						array_push($pictures, array("{$base}display/{$spath}", "thumb.php?image={$laalbum}{$file}"));
					}else{
						array_push($pictures, array("index.php?act=display&image={$spath}","thumb.php?image={$laalbum}{$file}"));
					}
				}
			}
		}
	}
	sort($albumlist);
	sort($pictures);
	closedir($dir_handle);
	$smarty->assign('pictures', $pictures);			
	$smarty->assign('albums', $albumlist);
	$smarty->assign('curalbum', $albumname);
	$smarty->assign('albumlist', $albumlist . "</ul>");
	$smarty->display("thumbs.tpl");
?>

